package com.lpwa.web.controller.system;

import java.util.List;

import com.lpwa.system.service.ITagLatestDataService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.lpwa.common.annotation.Log;
import com.lpwa.common.enums.BusinessType;
import com.lpwa.system.domain.TagLatestData;
import com.lpwa.common.core.controller.BaseController;
import com.lpwa.common.core.page.TableDataInfo;
import com.lpwa.common.core.domain.AjaxResult;
import com.lpwa.common.utils.poi.ExcelUtil;

/**
 * 标签数据 信息操作处理
 * 
 * @author tanmu
 * @date 2019-06-22
 */
@Controller
@RequestMapping("/system/tagLatestData")
public class TagLatestDataController extends BaseController
{
    private String prefix = "system/tagLatestData";
	
	@Autowired
	private ITagLatestDataService tagLatestDataService;
	
	@RequiresPermissions("system:tagLatestData:view")
	@GetMapping()
	public String tagLatestData()
	{
	    return prefix + "/tagLatestData";
	}
	
	/**
	 * 查询标签数据列表
	 */
	@RequiresPermissions("system:tagLatestData:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(TagLatestData tagLatestData)
	{
		startPage();
        List<TagLatestData> list = tagLatestDataService.selectTagLatestDataList(tagLatestData);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出标签数据列表
	 */
	@RequiresPermissions("system:tagLatestData:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TagLatestData tagLatestData)
    {
    	List<TagLatestData> list = tagLatestDataService.selectTagLatestDataList(tagLatestData);
        ExcelUtil<TagLatestData> util = new ExcelUtil<TagLatestData>(TagLatestData.class);
        return util.exportExcel(list, "tagLatestData");
    }
	
	/**
	 * 新增标签数据
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存标签数据
	 */
	@RequiresPermissions("system:tagLatestData:add")
	@Log(title = "标签数据", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(TagLatestData tagLatestData)
	{		
		return toAjax(tagLatestDataService.insertTagLatestData(tagLatestData));
	}

	/**
	 * 修改标签数据
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		TagLatestData tagLatestData = tagLatestDataService.selectTagLatestDataById(id);
		mmap.put("tagLatestData", tagLatestData);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存标签数据
	 */
	@RequiresPermissions("system:tagLatestData:edit")
	@Log(title = "标签数据", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(TagLatestData tagLatestData)
	{		
		return toAjax(tagLatestDataService.updateTagLatestData(tagLatestData));
	}
	
	/**
	 * 删除标签数据
	 */
	@RequiresPermissions("system:tagLatestData:remove")
	@Log(title = "标签数据", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(tagLatestDataService.deleteTagLatestDataByIds(ids));
	}
	
}
